#ifndef _POWER_H_
#define _POWER_H_

#include "lv_drv_conf.h"

#if USE_POWER_MODULE
#include "../../board.h"
#include "power_charger.h"

#define PM_BATTERY_STATE_NORMAL      0
#define PM_BATTERY_STATE_LOW         1
#define PM_BATTERY_STATE_CRITICAL    2
#define PM_BATTERY_STATE_SHUTDOWN    3
#define PM_BATTERY_STATE_UNKNOWN     4

#define PM_CHARGER_DISCONNECTED      0
#define PM_CHARGER_CONNECTED         1
#define PM_CHARGER_CHRGING           2
#define PM_CHARGER_FINISHED          3
#define PM_CHARGER_ERROR_TEMPERATURE 4
#define PM_CHARGER_ERROR_VOLTAGE     5
#define PM_CHARGER_ERROR_UNKNOWN     9

#define PMIC_BAD_VALUE 0xFFFF

typedef enum
{
    /// Charge with a  75 mA current
    PRE_CHARGER_75MA,
    /// Charge with a 50 mA current
    PRE_CHARGER_50MA,
    /// Charge with a 100 mA current
    PRE_CHARGER_100MA,
    /// Charge with a 150 mA current
    PRE_CHARGER_150MA,
} PRECHARGE_CURRENT_T;

typedef enum
{
    /// Charge with a  50 mA current
    TER_CHARGER_50MA,
    /// Charge with a 25 mA current
    TER_CHARGER_25MA,
    /// Charge with a 75 mA current
    TER_CHARGER_75MA,
    /// Charge with a 100 mA current
    TER_CHARGER_100MA,
} TERMINATION_CURRENT_T;

typedef enum
{
    BAT_VOLTAGE_4200MV,
    BAT_VOLTAGE_4350MV,
    BAT_VOLTAGE_4150MV,
    BAT_VOLTAGE_4100MV,
} BATTERY_VOLTAGE_T;

typedef enum
{
    TRICKIE_CHARGER_TOUT_6M,
    TRICKIE_CHARGER_TOUT_9M,
    TRICKIE_CHARGER_TOUT_12M,
    TRICKIE_CHARGER_TOUT_15M,
} TRICKIE_CHARGER_T;

typedef enum
{
    PRE_CHARGER_TOUT_24M,
    PRE_CHARGER_TOUT_26M,
    PRE_CHARGER_TOUT_48M,
    PRE_CHARGER_TOUT_60M,
} PRE_CHARGER_T;

typedef enum
{
    CCCV_TOUT_96M,
    CCCV_TOUT_144M,
    CCCV_TOUT_192M,
    CCCV_TOUT_240M,
} CCCV_CHARGER_T;

struct PMIC_BATTERY_LEVEL_CFG_T
{
    uint8_t battery_warning_threshold;
    uint8_t battery_level0_threshold;
    uint8_t battery_level1_threshold;
    uint8_t battery_level2_threshold;
    uint8_t battery_level3_threshold;
    uint8_t battery_level4_threshold;
};

typedef enum
{
    VBAT_VOL_4V20,
    VBAT_VOL_4V35,
    VBAT_VOL_4V15,
    VBAT_VOL_4V10,
    VBAT_VOL_4V30,
    VBAT_VOL_4V40,
    VBAT_VOL_4V55,
    VBAT_VOL_MAX=VBAT_VOL_4V55,

    /* added for Ningbo2 */
    VBAT_VOL_4V20_813S = VBAT_VOL_4V20,
    VBAT_VOL_4V25_813S,
    VBAT_VOL_4V30_813S,
    VBAT_VOL_4V35_813S,
    VBAT_VOL_4V40_813S,
    VBAT_VOL_4V45_813S,
    VBAT_VOL_4V15_813S,
    VBAT_VOL_4V10_813S,
    VBAT_VOL_MAX_813S=VBAT_VOL_4V10_813S,
}VBAT_VOLTAGE;

typedef struct PMIC_CONFIG_STRUCT_T
{
    /// usually 4200 (4.2V) for LiIon batteries.
    uint16_t batteryLevelFullMV;
    uint16_t batteryLevelPrechargeMV;
    //UINT32 batteryChargeTimeout;
    uint16_t battery_termination_cur_mA;
    /// the power-on battery level in milivolts
    uint16_t powerOnVoltageMV;
    /// the power-down battery level in milivolts
    uint16_t powerDownVoltageMV;
    /// the battery charge current
    PMIC_CHARGE_CURRENT_T batteryChargeCurrent;
    uint32_t mppt_CurrentUpperLimit;
    PRECHARGE_CURRENT_T pre_charge_Current;
    TERMINATION_CURRENT_T termination_charger_Current;
    VBAT_VOLTAGE battery_cv_Voltage;
    TRICKIE_CHARGER_T trickle_ChargeTimeout;
    PRE_CHARGER_T pre_Charge_Timeout;
    CCCV_CHARGER_T cccv_Charge_Timeout;
    uint16_t batteryIR;
    uint16_t recharger_vol_mV;
    BOOL charger_rise_up_vol;
    BOOL Has_battery_discharger_table;
    unsigned short BatteryDischarger_table[101];
    BOOL Has_battery_temp;
    uint32_t battery_temp[29];
}PMIC_CONFIG_T;

typedef int (*Usb_PlugCallback)(unsigned int action);
typedef unsigned int (*Sim_CallCallback)(unsigned int SimId);
typedef int (*Battery_Callback)(unsigned char bcs,unsigned char bcl,unsigned short batLevel);
BOOL ChargerCallbackRegister(Usb_PlugCallback Usb_charger_status,Sim_CallCallback get_call_status,Battery_Callback battery_status);
BOOL pm_BatteryInit(void);
BOOL pm_BatteryMonitorProc(void);
#endif

#endif
